package com.sanjiahantang.youjiarole.module.article.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.article.beans.ArticleResponseBean;
import com.sanjiahantang.youjiarole.module.article.beans.ArticleTypeListResponseBean;
import com.sanjiahantang.youjiarole.module.article.models.IArticleModel;
import com.sanjiahantang.youjiarole.module.common.beans.HelpBean;
import com.sanjiahantang.youjiarole.module.common.beans.RichTextBean;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by zy on 2017/10/30.
 */

public class ArticleModel implements IArticleModel {
    @Override
    public void searchArticleTypeRole(final Context context, Map<String, Object> param, final CallBack<ArticleTypeListResponseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/article/role/searchArticleTypeRole", param, new BaseDelegate.ResultCallback<ArticleTypeListResponseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ArticleTypeListResponseBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }

    @Override
    public void findArTrainByIdRole(final Context context, Map<String, String> param, final CallBack<ArticleResponseBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/article/role/findArTrainByIdRole", param, new BaseDelegate.ResultCallback<ArticleResponseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ArticleResponseBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }

    @Override
    public void searchArTrainInfoType(final Context context, Map<String, Object> param, final CallBack<ArticleTypeListResponseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/article/role/searchArTrainInfoType", param, new BaseDelegate.ResultCallback<ArticleTypeListResponseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ArticleTypeListResponseBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }

    @Override
    public void searchArTrainInfoRole(final Context context, Map<String, Object> param, final CallBack<ArticleTypeListResponseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/article/role/searchArTrainInfoRole", param, new BaseDelegate.ResultCallback<ArticleTypeListResponseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ArticleTypeListResponseBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }

    @Override
    public void findNoticeInfoById(final Context context, Map<String, String> param, final CallBack<RichTextBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/system/notice/findNoticeInfoById", param, new BaseDelegate.ResultCallback<RichTextBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(RichTextBean response, Object tag) {
                callBack.onSuccess(response, context, null);
            }
        });
    }
}
